package me.w70.bot.wrappers;

import java.util.LinkedList;
import java.util.List;

import me.w70.bot.Bot;

/**
 * Created by IntelliJ IDEA. User: Jan Ove / Kosaki Date: 22.mar.2009 Time:
 * 20:15:45
 */
public class RSInterfaceGroup {
	private me.w70.hooks.Interface[] interfaces;

	private int index = -1;

	public RSInterfaceGroup(me.w70.hooks.Interface[] interfaces, int index) {

		this.index = index;
		this.interfaces = interfaces;
	}

	/**
	 * gets an interface.
	 * 
	 * @param interfaceID
	 * @return may return null if interface does not exist.
	 */
	public RSInterface getInterface(int interfaceID) {
		if (interfaceID < 0 || interfaceID >= interfaces.length)
			return null;
		return new RSInterface(interfaces[interfaceID], null);
	}

	public int getIndex() {
		return index;
	}

	public RSInterface[] getChildren() {
		List<RSInterface> out = new LinkedList<RSInterface>();
		for (me.w70.hooks.Interface face : interfaces) {
			out.add(new RSInterface(face, null));
		}
		return out.toArray(new RSInterface[1]);
	}

	/**
	 * Hack for interface debugger
	 * 
	 * @return
	 */
	public String toString() {
		return "" + index;
	}

	public boolean isValid() {
		if (interfaces == null)
			return false;
		boolean[] validArray = Bot.methods.getClient().getValidInterfaceArray();
		if (validArray == null)
			return true; // As the interface group actually exists
		return index == -1 || validArray[index];
	}
}
